package com.itheima.d6_TCP6;

import java.net.ServerSocket;
import java.net.Socket;
import java.util.LinkedList;
import java.util.List;
import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.Executors;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

public class Server {
    public static List<Socket> onLineSockets =new LinkedList<>();
    public static void main(String[] args)throws Exception {
        System.out.println("服务端启动成功");

        ServerSocket serverSocket =new ServerSocket(8881);

        ThreadPoolExecutor pool =new ThreadPoolExecutor(16*2,16*2,0,TimeUnit.SECONDS,
                new ArrayBlockingQueue<>(8), Executors.defaultThreadFactory(),
                new ThreadPoolExecutor.AbortPolicy());



        while (true){
            Socket socket = serverSocket.accept();
            onLineSockets.add(socket);
            System.out.println("有人上线了"+socket.getRemoteSocketAddress());
            pool.execute(new ServerReaderRunnable(socket));
        }

    }
}
